/*-
 * SelectPhonebookMemoryStorage.java
 *
 * $LastChangedBy:  $
 * $LastChangedRevision:  $
 * $LastChangedDate:  $
 * $HeadURL: $
 *
 * Copyright (c) 2008, Stein Gunnar Bakkeby
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Stein Gunnar Bakkeby nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.googlecode.attention;

/**
 * List of possible mobile phonebook memory storages. Not all of these will be
 * available on every phone.
 *
 * @author Stein Gunnar Bakkeby
 */
public enum PhonebookMemoryStorage {

  /** SIM phonebook (storage depends on SIM Card) */
  SIM("SM", true),
  /** The main combined phonebook (phone, email, all in one) */
  AD("AD", true),
  /**
   * SIM fixdialling phonebook.
   * If the mobile is locked to FD, only the numbers stored to the
   * FD memory can be dialled. To edit the FD phonebook PIN 2
   * is required. See AT+CLCK Facility lock and AT^SLCK Facility
   * lock (including self-defined locks).
   */
  SIM_FIXDIALLING("FD", true),
  /**
   * Quick dial phonebook.
   */
  QUICK_DIAL("QD", true),
  /**
   * SIM last-dialling-phonebook.
   * (Writing entries to this storage not applicable)
   */
  LAST_DIALLED("LD", false),
  /**
   * The dialled calls phonebook, essentially the same as "LD" (last dialled).
   * (Writing entries to this storage not applicable)
   */
  DIALLED_CALLS("DC", false),
  /**
   * ME missed (unanswered received) calls) list.
   * (Writing entries to this storage not applicable)
   */
  MISSED_CALLS("MC", false),
  /**
   * ME received calls list.
   * (Writing entries to this storage not applicable)
   */
  RECEIVED_CALLS("RC", false),
  /**
   * SIM (or ME) own numbers (MSISDNs) list. E.g. the number associated with
   * the current SIM card.
   */
  OWN_NUMBERS("ON", true),
  /**
   * Emergency numbers phonebook.
   */
  EMERGENCY_NUMBERS("EN", true),
  /**
   * ME Phonebook.
   */
  MOBILE("ME", true),
  /**
   * Service Dialling Numbers.
   */
  SERVICE_DIALLING_NUMBERS("SD", true),
  /**
   * Barred Dialling Numbers.
   */
  BARRED_NUMBERS("BD", true),
  /**
   * Combined ME and SIM phonebook.
   */
  MOBILE_SIM_COMBINED("MT", true),
  /**
   * Unknown memory storage.
   */
  UNKNOWN("", false);
  
  private final String reference;
  private final boolean canWrite;
  
  private PhonebookMemoryStorage(final String ref, final boolean canWrite) {
    this.reference = ref;
    this.canWrite = canWrite;
  }

  /**
   * This will return the memory storage associated with the given string
   * reference.
   * 
   * @param reference Reference associated with the memory storage
   * @return The corresponding memory storage
   */
  public static PhonebookMemoryStorage getPhonebookMemoryStorage(
      final String reference) {
    for (PhonebookMemoryStorage pms : PhonebookMemoryStorage.values()) {
      if (reference.equals(pms.reference)) return pms;
    }
    return UNKNOWN;
  }
  
  /**
   * Indicates whether it is possible to write to this memory storage.
   * 
   * @return True if it should be possible to write to this memory storage,
   *         false otherwise
   */
  public boolean canWrite() {
    return canWrite;
  }
  
  /**
   * This will return the string reference identifying the storage. Used in
   * relation to AT commands.
   * 
   * @return Text reference
   */
  public String getReference() {
    return reference;
  }
}